<include file="Public:header" />
<div class="page-member subpage">
    <div class="form-header">
        <div>
            <div class="line1">
                <div class="fl"><h3>维修单信息 / 新增</h3></div>
                <div class="fr hidden">
                    <form class="search-form" method="post" action="">
                        <input name="field" value="{$filter.field}" type="text" />
                        <input name="value" value="{$filter.value}" type="text" />
                        <input name="page" value="{$filter.page}" type="hidden" />
                        <input name="order_field" value="{$filter.order_field}" type="hidden" />
                        <input name="order_sort" value="{$filter.order_sort}" type="hidden" />
                        <button class="btn-normal" type="submit">查 询</button>
                    </form>
                </div>
            </div>
            <div class="line2">
                <div class="fl form-btn-group">
                    <in name="$x|default='02-03-16'" value="$rightsCode">
                        <button onclick="submitForm();" class="btn-save btn-highlight">保 存</button>
                        <else />
                        <button disabled="disabled" class="btn-save btn-disable">保 存</button>
                    </in>
                    <span>或</span>
                    <a class="linkBtn btn-abort" href="/admin/repair/index">放弃</a>
                </div>
            </div>
        </div>
    </div>
    <div class="form-box2">
        <div>
            <form id="repairForm" method="post" action="">
                <input type="hidden" name="id" id="id" value="{$repair.id}" />
                <table class="form">
                    <tr>
                        <th width="15%">维修类型<span class="hint">*</span></th>
                        <td width="35%">
                            <input type="checkbox" checked="checked" name="type" value="租赁区域" />
                            <label>租赁区域</label>
                            <input type="checkbox" name="type" value="公共区域" />
                            <label>公共区域</label>
                        </td>
                        <th width="15%" style="border:0;"></th>
                        <td></td>
                    </tr>
                    <tr>
                        <th>小区名称<span class="hint">*</span></th>
                        <td>
                            <select name="community_id">
                                <option>--请选择小区--</option>
                                <volist name="community" id="vo">
                                    <option <if condition="$vo eq $repair[community_id]">selected="selected"</if> value="{$vo.id}">{$vo.name}</option>
                                </volist>
                            </select>
                        </td>
                        <th>房源地址</th>
                        <td><input name="house_addr" disabled="disabled" type="text" value="{$repair.house_addr}" /> </td>
                    </tr>
                    <tr>
                        <th>报修人<span class="hint">*</span></th>
                        <td><input name="bxr" type="text" value="{$repair.bxr}" /> </td>
                        <th>报修电话<span class="hint">*</span></th>
                        <td><input name="bxdh" type="text" value="{$repair.bxdh}" /> </td>
                    </tr>
                    <tr>
                        <th>报修日期<span class="hint">*</span></th>
                        <td colspan="3"><input name="bxrq" type="text" value="{$repair.bxrq|default=time()|date='Y/m/d',###}" /> </td>
                    </tr>
                    <tr>
                        <th>文字描述<span class="hint">*</span></th>
                        <td colspan="3">
                            <textarea placeholder="请输入报修描述，200字以内" style="width:310px;height:100px;" name="bxms">{$repair.bxms}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <th>图片描述<span class="hint">*</span></th>
                        <td colspan="3">
                            <input name="upload" class="hidden" type="file" />
                            <input name="xc1_Img" type="hidden" value="{$repair.xc1_Img}" />
                            <input name="xc2_Img" type="hidden" value="{$repair.xc2_Img}" />
                            <input name="xc3_Img" type="hidden" value="{$repair.xc3_Img}" />
                            <input name="xc4_Img" type="hidden" value="{$repair.xc4_Img}" />
                            <img name="xc1_Img" style="margin-top:10px;width:150px;height:120px;" class="img-upload" src="__IMG__/xc1.png" />
                            <img name="xc2_Img" style="margin-top:10px;width:150px;height:120px;" class="img-upload" src="__IMG__/xc2.png" />
                            <img name="xc3_Img" style="margin-top:10px;width:150px;height:120px;" class="img-upload" src="__IMG__/xc3.png" />
                            <img name="xc4_Img" style="margin-top:10px;width:150px;height:120px;" class="img-upload" src="__IMG__/xc4.png" />
                        </td>
                    </tr>
                    <tr style="vertical-align: top;">
                        <th>备注</th>
                        <td colspan="3"><textarea placeholder="请输入备注信息" style="width:310px;" name="remarks">{$repair.remarks}</textarea></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
<link type="text/css" href="__JS__/autocomplete2/src/jquery.autocomplete.min.css" rel="stylesheet">
<script src="__JS__/autocomplete2/src/jquery.autocomplete.js" type="text/javascript"></script>
<script>

    function fn_GetType(){
        var flag = false
        $("input[name='type']").each(function(){
            if($(this).is(":checked")
                    && $(this).val()=='租赁区域'){
                flag = true;
            }
        });
        return flag;
    }

    $("select[name=community_id]").change(function(){
        var flag = fn_GetType();
        if($(this).val() && flag){
            $("input[name=house_addr]").val("").attr("disabled", false);
        }else{
            $("input[name=house_addr]").val("").attr("disabled", true);
        }

        var community_id = $(this).val();
        $('input[name=house_addr]').autocomplete({
            minChars: 3,
            serviceUrl: '/admin/repair/ajax_SearchHouseByName',
            params: {community_id: community_id},//动态参数值
            paramName: "house",
            onSelect: function (suggestion) {
                $("input[name=bxr]").val(suggestion.data.zhname);
                $("input[name=bxdh]").val(suggestion.data.phone);
                $("input[name=house_addr]").val(suggestion.data.addr);
            }
        });
    });

    $("input[name=type]").click(function(){
        if($(this).prop("checked")){
            $("input[name=type]").prop("checked", false);
            $(this).prop("checked", true);
            if($("select[name=community_id]").val()){
                $("input[name=house_addr]").val("").attr("disabled", true);
            }else{
                $("input[name=house_addr]").val("").attr("disabled", false);
            }
        }
    });

    $(document).ready(function(){
        $(".img-upload").click(function () {
            $("input[name=upload]").prop("mb", $(this).prop("name")).click();
        });
        $("input[name=upload]").change(function () {
            var self = $(this);
            var form_data = new FormData();
            var file_data = self.prop('files')[0];
            form_data.append('file', file_data);
            $.ajax({
                url: '/home/index/ajax_UploadImg',
                dataType: 'json',
                contentType: false,
                processData: false,
                data: form_data,
                type: 'post',
                success: function(res){
                    if(res.status){
                        self.val(""); //重置文件上传框
                        $("img[name="+self.prop("mb")+"]").prop("src", res.info);
                        $("input[name="+self.prop("mb")+"]").val(res.info);
                    }else{
                        alert(res.info);
                    }
                }
            });
        });
    });
</script>
<script src="__JS__/repair.js?v=0.3" type="text/javascript" ></script>
<include file="Public:footer" />
